﻿// Groupon.NET C# Library
// Copyright (c) 2011 James Paul Duncan (JPaulDuncan)
// The MIT License (MIT)
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE. 
// http://www.jpaulduncan.com

namespace Groupon.Net
{
    /// <summary>
    /// Represents a location.
    /// </summary>
    public sealed class Location : ModelBase
    {        
        private string _name;
        private string _address1;
        private string _address2;
        private string _city;
        private string _state;
        private string _postalCode;
        private GeoCode _geoCode;

        public Location()
            : base()
        {
            _geoCode = new GeoCode();
        }

        public string Name
        {
            get { return _name; }
            set { base.SetProperty<string>("Name", ref _name, value); }
        }

        public string StreetAddress1
        {
            get { return _address1; }
            set { base.SetProperty<string>("StreetAddress1", ref _address1, value); }
        }

        public string StreetAddress2
        {
            get { return _address2; }
            set { base.SetProperty<string>("StreetAddress2", ref _address2, value); }
        }

        public string City
        {
            get { return _city; }
            set { base.SetProperty<string>("City", ref _city, value); }
        }

        public string State
        {
            get { return _state; }
            set { base.SetProperty<string>("State", ref _state, value); }
        }

        public string PostalCode
        {
            get { return _postalCode; }
            set { base.SetProperty<string>("PostalCode", ref _postalCode, value); }
        }

        public GeoCode GeoCode
        {
            get { return _geoCode; }
            set { base.SetProperty<GeoCode>("GeoCode", ref _geoCode, value); }
        }

        internal static Location Parse(System.Xml.XmlNode xmlNode)
        {
            Location result = new Location();

            if (xmlNode != null)
            {
                result.City = xmlNode.SelectSingleNode("city").GetText();
                result.GeoCode = new GeoCode();
                result.GeoCode.Latitude = xmlNode.SelectSingleNode("lat").GetText();
                result.GeoCode.Longitude = xmlNode.SelectSingleNode("lng").GetText();
                result.Name = xmlNode.SelectSingleNode("name").GetText();
                result.PostalCode = xmlNode.SelectSingleNode("postalCode").GetText();
                result.State = xmlNode.SelectSingleNode("state").GetText();
                result.StreetAddress1 = xmlNode.SelectSingleNode("streetAddress1").GetText();
                result.StreetAddress2 = xmlNode.SelectSingleNode("streetAddress2").GetText();
            }

            return result;
        }

    }
}
